package com.java.test.agent.module.feescale;

import com.java.test.agent.module.feescale.dto.AgentFeeScaleDTO;
import com.java.test.agent.module.feescale.entity.AgentFeeScaleEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * DAO
 *
 * @author lijie1
 * @date 2020/6/30 0030
 */
@Component
public class AgentFeeScaleDao {

    private JdbcTemplate jdbcTemplate;
    @Autowired
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    /**
     * 查询默认比例
     * @author lijie1
     * @date 2020/7/1 0001
     */
    public AgentFeeScaleEntity getEntity() {
        String sql = "select * from agent_fee_scale";

        List<AgentFeeScaleEntity> list = jdbcTemplate.query(sql,new AgentFeeScaleEntity());

        return list.get(0);
    }

    /**
     * 修改代理默认费率
     * @author lijie1
     * @date 2020/7/1 0001
     */
    public void update(AgentFeeScaleDTO dto) {
        String sql = "update agent_fee_scale " +
                "set  feescale = ?,brokeragescale = ? ";

        jdbcTemplate.update(sql, dto.getFeeScale(),dto.getBrokerageScale());
    }
}
